package com.zhiyizhen.handheld.component.execute.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.zhiyizhen.handheld.common.DataCache;
import com.zhiyizhen.handheld.common.view.adapter.recyclerview.BaseAdapter;
import com.zhiyizhen.handheld.common.view.adapter.recyclerview.BaseViewHolder;
import com.zhiyizhen.handheld.component.execute.bean.executedetail.ExtInfoBean;
import com.zhiyizhen.handheld.component.main.bean.EnumFieldBean;
import com.zhiyizhen.handheld.databinding.ItemWaizhiGroupBinding;

import java.util.List;

public class ExecuteWaizhiGroupAdapter extends BaseAdapter<ExtInfoBean.DetailListBean, ExecuteWaizhiGroupAdapter.ShuyeGroupViewHolder> {

    public ExecuteWaizhiGroupAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ShuyeGroupViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ShuyeGroupViewHolder(this, ItemWaizhiGroupBinding.inflate(LayoutInflater.from(parent.getContext())));
    }

    class ShuyeGroupViewHolder extends BaseViewHolder<ExtInfoBean.DetailListBean> {

        private final ItemWaizhiGroupBinding binding;

        public ShuyeGroupViewHolder(BaseAdapter<ExtInfoBean.DetailListBean, ShuyeGroupViewHolder> adapter, ItemWaizhiGroupBinding viewBinding) {
            super(adapter, viewBinding.getRoot());
            binding = viewBinding;
        }

        @Override
        public void bindData(ExtInfoBean.DetailListBean data) {
            binding.acupointNameTv.setText(data.getAcupointName());
            String sideTypeString = "";
            List<EnumFieldBean> acupointSideTypeEnum = DataCache.getEnumsBean().getEnums().getAcupointSideTypeEnum();
            if (acupointSideTypeEnum != null) {
                for (EnumFieldBean execStatus : acupointSideTypeEnum) {
                    if (execStatus.getValue().equals(data.getSideType())) {
                        sideTypeString = execStatus.getText();
                        break;
                    }
                }
            }
            binding.typeTv.setText(sideTypeString);
        }
    }

}